home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / msj / v06n04 / time.exe / TIMER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  1.5 KB  |  53 lines

  1. /*----------------------------------------------------------------------------
  2.  *
  3.  *  Sample code on how to use the new GetLowTickCount().
  4.  *
  5.  *  To use:  "cl -c -Gs -W4 timer.c"
  6.  *           "masm /D?WIN=0 tick.asm;"
  7.  *           "link timer tick;"
  8.  *
  9.  *--------------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12.  
  13. /*--- Prototype the new tick count function ---*/
  14. unsigned long far pascal GetLowTickCount( void );
  15.  
  16. unsigned long SyncTime( void );
  17.  
  18. void main()
  19. {
  20.     unsigned long dwTick;               /*  returned tick count  */
  21.     long lTimesSec;                     /*  counts calls/sec     */
  22.     long loop;                          /*  misc looping var     */
  23.  
  24.     /*--- How many GetLowTickCount() calls can be made in one second ---*/
  25.     lTimesSec = 0;
  26.     dwTick = SyncTime();
  27.     while (GetLowTickCount()<(dwTick+1000)) {
  28.         ++lTimesSec;
  29.         }
  30.     printf( "Number of GetLowTickCount() calls/sec = %ld\n", lTimesSec );
  31.  
  32.     /*--- Time 100,000 long multiplies ---*/
  33.     dwTick = SyncTime();
  34.     for (loop=0; loop<100000; ++loop) {
  35.         long l = loop*12345;
  36.         }
  37.     dwTick = GetLowTickCount()-dwTick;
  38.     printf( "100000 long multiplies = %lu\n", dwTick );
  39.  
  40. } /* main */
  41.  
  42. unsigned long SyncTime()
  43. {
  44.     unsigned long dw1, dw2;
  45.  
  46.     /*--- Wait for a millisecond boundary ---*/
  47.     dw1 = GetLowTickCount();
  48.     while (dw1==(dw2=GetLowTickCount()))
  49.         ;
  50.     return (dw2);
  51.  
  52. } /* SyncTime */
  53.